<template>
  <div>
     <!-- 选择题,单选 -->
   题目： <input type="text" v-model="datas.title" placeholder="请输入题目" />
    A选项内容 <input type="text" v-model="datas.A" placeholder="请输入选项信息" />
    B选项内容 <input type="text" v-model="datas.B" placeholder="请输入选项信息" />
    C选项内容 <input type="text" v-model="datas.C" placeholder="请输入选项信息" />
    D选项内容 <input type="text" v-model="datas.D" placeholder="请输入选项信息" />
   请选择课程信息:<select v-model="datas.course">
      <option value="1">语文</option>
      <option value="2">英语</option>
      <option value="3">数学</option>
      <option value="4">前端</option>
    </select>
    参考答案 <input type="text" v-model="datas.answer" placeholder="请输入参考答案" />
    <input type="button" @click="subSelect"  value="提交"/>



    <div class="modal fade" id="staticBackdrop" data-backdrop="static" data-keyboard="false" tabindex="-1" role="dialog" aria-labelledby="staticBackdropLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="staticBackdropLabel">Modal title</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            ...
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
            <button type="button" class="btn btn-primary">Understood</button>
          </div>
        </div>
      </div>
    </div>


    <!-- <button type="button"  class="btn btn-primary" data-toggle="modal" data-target="#staticBackdrop">
      Launch static backdrop modal
    </button> -->

  </div>
</template>

<script>
  import Vue from 'vue';
  import $ from 'jquery';
  export default{
    name:"selects",
    data:()=>{
      return{
        datas:{
          title:"",
          A:"",
          B:"",
          C:"",
          D:"",
          answer:"",
          course:"4"
        }
      }
    },
    created:function(){
      $("#btn").click();
    },
    methods:{
      subSelect:function(){
        let that = this;
        console.log(this.datas);
        console.log('保存的地址：' + this.$store.state.localhost)
        if(!this.datas.title || !this.datas.A || !this.datas.B || !this.datas.answer){
          alert("除选项CD外，其余项不能为空");
          return;
        }
        $.ajax({
          url:this.$store.state.localhost + "insertSelect",
          type:'post',
          dataType:'json',
          data:that.datas,
          success:(res)=>{
            console.log(res);
            if(res.status){
               console.log(res.info);
               this.$router.push('/examList');
            }else{
              alert(res.info);
            }
          },
          error:(err)=>{
            console.log(err);
          }
        })
      }
    }
  }
</script>

<style scoped="scoped">
  input,select{
    width: 250px;
    height: 40px;
    display: block;
    margin-top: 10px;
  }

</style>
